package com.huobao.yunying.activitys;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.xutils.view.annotation.ViewInject;

import com.ab.view.sliding.AbSlidingTabView;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.entity.DaiLiType;
import com.huobao.yunying.fragments.Fragment_DailiPin;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpConst;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.zhangying.R;

import android.app.Fragment;
import android.graphics.Color;

/**
 * 代理品
 * 
 * @author Administrator
 *
 */
public class Act_Dailipin extends HuobaoBaseActivity {

	private Http m_Http;
	@ViewInject(R.id.tabview)
	private AbSlidingTabView mAbSlidingTabView;

	@Override
	protected int getContentView() {
		return R.layout.layout_dailipin;
	}

	@Override
	protected String getTitleText() {
		return "代理品";
	}

	@Override
	protected void init() {
		m_Http = Http.getInstant();
		// 缓存数量
		mAbSlidingTabView.getViewPager().setOffscreenPageLimit(5);
		mAbSlidingTabView.setTabTextColor(Color.BLACK);
		mAbSlidingTabView.setTabSelectColor(Color.rgb(30, 168, 131));
		mAbSlidingTabView.setTabBackgroundResource(R.drawable.tab_bg);
		mAbSlidingTabView.setTabLayoutBackgroundResource(R.mipmap.slide_top);
		mAbSlidingTabView.setTabPadding(20, 8, 20, 8);
		getTypes();
	}
	
	private void getTypes(){
		Map<String, String> map = HttpUtil.getParams(HttpConst.FRIST_KEY,HttpConst.dlp);
		m_Http.sendRequest(this, map, new HttpListener() {
			
			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				List<DaiLiType> list = JSON.parseArray(jsonObject.getString("retval"), DaiLiType.class);
				List<String> tabTexts = new ArrayList<String>();
				List<Fragment> mFragments = new ArrayList<Fragment>();
				for(DaiLiType type:list){
					tabTexts.add(type.getCate_name());
					Fragment_DailiPin fragment_DailiPin = Fragment_DailiPin.getInstant(type.getCate_id());
					mFragments.add(fragment_DailiPin);
				}
				mAbSlidingTabView.addItemViews(tabTexts, mFragments);
				mAbSlidingTabView.setTabPadding(20, 8, 20, 8);
			}
			
			@Override
			public void onHttpError(String error) {
			}
		});
	}

}
